﻿/*******************************************************************************
 * Copyright © Chris Watson 2013                                               *
 *                                                                             *
 * This document is a part of the source code and related artefacts for Chris  *
 * Watson's Desktop Wallpaper Guard, a software application which will detect  *
 * when another process removes the wallpaper from a Windows desktop and       *
 * restore an image of the user's choice.                                      *
 *                                                                             *
 * Author:                                                                     *
 *   Chris Watson       [mailto:chris@watson.me.uk]                            *
 * Date:                                                                       *
 *   17 August 2013                                                            *
 ******************************************************************************/

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Watson.BleaknessEliminator.Properties;

namespace Watson.BleaknessEliminator
{
    /// <summary>
    /// Provides an interface for the user to select certain program options.
    /// </summary>
    internal partial class OptionsForm : Form
    {
        #region Private Methods

        /// <summary>
        /// Handles the Click event of the btnApply control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void btnApply_Click(object sender, EventArgs e)
        {
            SaveOptions();
        }


        /// <summary>
        /// Handles the Click event of the btnBrowseForWallpaper control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void btnBrowseForWallpaper_Click(object sender, EventArgs e)
        {
            if (wallpaperOpenFileDialog.ShowDialog() == DialogResult.OK)
            {
                txtWallpaperPath.Text = wallpaperOpenFileDialog.FileName;
            }
        }


        /// <summary>
        /// Handles the Click event of the btnCancel control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void btnCancel_Click(object sender, EventArgs e)
        {
            DialogResult = DialogResult.Cancel;

            Close();
        }


        /// <summary>
        /// Handles the Click event of the btnOK control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="EventArgs"/> instance containing the event data.
        /// </param>
        private void btnOK_Click(object sender, EventArgs e)
        {
            SaveOptions();

            DialogResult = DialogResult.OK;

            Close();
        }


        /// <summary>
        /// Initialises the form icon.
        /// </summary>
        private void InitialiseFormIcon()
        {
            // Set form icon.
            //
            this.Icon = Resources.Icon;
        }


        /// <summary>
        /// Handles the LinkClicked event of the lnklblCopyCurrentWallpaperPath
        /// control.
        /// </summary>
        /// <param name="sender">
        /// The source of the event.
        /// </param>
        /// <param name="e">
        /// The <see cref="LinkLabelLinkClickedEventArgs"/> instance containing
        /// the event data.
        /// </param>
        private void lnklblCopyCurrentWallpaperPath_LinkClicked(object sender,
            LinkLabelLinkClickedEventArgs e)
        {
            // Obtain the path to the current desktop wallpaper.
            //
            string path = WindowsProfileSettings.GetWallpaper();

            txtWallpaperPath.Text = path;
        }


        /// <summary>
        /// Loads the options from the <see cref="Settings"/> into the form's
        /// controls.
        /// </summary>
        private void LoadOptions()
        {
            txtWallpaperPath.Text = Settings.Default.WallpaperPath;
        }


        /// <summary>
        /// Saves the options selected or entered by the user to the
        /// <see cref="Settings"/>.
        /// </summary>
        private void SaveOptions()
        {
            Settings.Default.WallpaperPath = txtWallpaperPath.Text;

            // Persist settings.
            //
            Settings.Default.Save();
        }
        
        #endregion

        #region Internal Constructors

        /// <summary>
        /// Initialises a new instance of the <see cref="OptionsForm"/> class.
        /// </summary>
        internal OptionsForm()
        {
            InitializeComponent();

            // Set form icon.
            //
            InitialiseFormIcon();

            // Load options from settings into form controls.
            //
            LoadOptions();
        }
        
        #endregion
    }
}
